<template>
  <div>
<van-picker
  title="标题"
  show-toolbar
  :columns="columns"
  @confirm="onConfirm"
  @cancel="onCancel"
  @change="onChange"
  :default-index="value"
/>
  </div>
</template>

<script>
import { updateUserProfile } from '@/api/user'
export default {
  name: 'UpdateGender',
  props: {
    value: Number
  },
  data () {
    return {
      columns: ['男', '女'],
      currentValue: this.value
    }
  },
  components: {},
  created () {},
  mounted () {},
  methods: {
    async onConfirm (value, index) {
      // 发请求
      await updateUserProfile({ gender: this.currentValue })
      // 提示成功
      this.$toast.success('修改成功')
      // 修改数据
      this.$emit('input', this.currentValue)
      // 关闭弹层
      this.$emit('close')
    },
    onChange (picker, value, index) {
      this.currentValue = index
    },
    onCancel () {
      this.$emit('close')
    }
  }
}
</script>

<style lang="less" scoped>

</style>
